package com.hlbbcsr.action;
 
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import com.opensymphony.xwork2.ActionSupport;
 
public class DownloadAction extends ActionSupport{
 	
	private String statementId;
	private InputStream fileInputStream;
	private String fileName;
 
	public InputStream getFileInputStream() {
		return fileInputStream;
	}
	public String getFileName() {
		return fileName;
	}	
 
	/**
	 * Read From File
	 */
	public String execute2() throws Exception {
	    fileInputStream = new FileInputStream(new File("D:\\lib\\new.pdf"));
	    fileName        = "file_name_here_from_pdf.pdf";
	    return SUCCESS;
	}

	/**
	 * iText Example
	 */
	public String execute() throws Exception {
		try {
			
			System.out.println("statementId = " + statementId);
			
			Document document = new Document();
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			PdfWriter.getInstance(document, baos);
			document.open();
			document.add(new Paragraph("success PDF FROM STRUTS"));
			document.close();
			
			fileInputStream = new ByteArrayInputStream(baos.toByteArray());
			fileName        = "file_name_here_by_iText.pdf";

		} catch (Exception e) {
			System.out.println(e);
		}
		return SUCCESS;
	}
	public String getStatementId() {
		return statementId;
	}
	public void setStatementId(String statementId) {
		this.statementId = statementId;
	}

}